<!DOCTYPE html>
<html>
  <head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  <meta name="author" content="紫锦木">
  

  <title>oss点单登录 | 紫锦木</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
  <meta name="keywords" content="PHP,oss点单登录,">
  

  
  <meta name="description" content="单点登录（Single Sign On），简称为 SSO，是比较流行的企业业务整合的解决方案之一。SSO 的定义是在多个应用系统中，用户只需要登录一次就可以访问所有相互信任的应用系统。@百度百科baike.baidu.com/item/%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95">

  

  
  <script src="//cdn.jsdelivr.net/npm/leancloud-storage@3.11.1/dist/av-min.js" async></script>
  

  
  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
  

  
  <script src="//unpkg.com/valine/dist/Valine.min.js" async></script>
  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"3zwI0gU7grT0MfYUEurqXnWE-gzGzoHsz","appkey":"yVgwglQXfL3vbQiSzeo1Xhqx","comment":true,"count":true},
    welcome: {"enable":false,"interval":30},
    start_time: "2019-05-01",
    passwords: ["efe07af7441da2b69c4a41e42e73be4db47f66010a56900788a458354a7373ec", ],
    is_post: true,
    lock: false,
    author: "紫锦木",
    share: {"twitter":false,"facebook":false,"weibo":true,"qq":true,"wechat":true},
    mathjax: true,
    page_type: "",
    root: "/"
  };
</script>

  <script src="/vendor/sha256.min.js"></script>
<script src="/js/auth.js"></script>
<script src="/js/index.js"></script>
<script src="/vendor/qrcode.min.js"></script>

  
  <link rel="icon" href="/images/favicon.ico">
  <link rel="apple-touch-icon" href="/images/touch-icon.png">
  

  <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <link rel="stylesheet" href="/css/index.css">
<link rel="stylesheet" href="/styles/components/highlight/highlight.css">

  
</head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/">紫锦木</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 足迹👣</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/" target="_self">首页</a>
      
        <a href="/archives/" target="_self">归档</a>
      
        <a href="/tags/" target="_self">标签</a>
      
        <a href="/categories/" target="_self">分类</a>
      
        <a href="/friends/" target="_self">友链</a>
      
        <a href="/about/" target="_self">关于</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://github.com/xfjpeter/" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/" target="_self">
            首页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/friends/" target="_self">
            友链
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/about/" target="_self">
            关于
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2020-02-23
    </span>
    
      <span>
        | <a href="/categories/PHP/"><i class="fa fa-bookmark"></i>PHP</a>
      </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
  </div>
  <h1 class="passage-title">
    oss点单登录
  </h1>
  
  <article class="passage-article">
    <blockquote><p>单点登录（Single Sign On），简称为 SSO，是比较流行的企业业务整合的解决方案之一。SSO 的定义是在多个应用系统中，用户只需要登录一次就可以访问所有相互信任的应用系统。</p>
<footer><strong>@百度百科</strong><cite><a href="https://baike.baidu.com/item/%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95" target="_blank" rel="noopener">baike.baidu.com/item/%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95</a></cite></footer></blockquote>
<h2 id="系统架构说明"><a href="#系统架构说明" class="headerlink" title="系统架构说明"></a>系统架构说明</h2><ol>
<li><a href="http://a.oss.centos.local" target="_blank" rel="noopener">http://a.oss.centos.local</a></li>
<li><a href="http://b.oss.centos.local" target="_blank" rel="noopener">http://b.oss.centos.local</a></li>
<li><a href="http://login.oss.centos.local" target="_blank" rel="noopener">http://login.oss.centos.local</a> (专门登录用的)</li>
</ol>
<h2 id="login-中的代码如下"><a href="#login-中的代码如下" class="headerlink" title="login 中的代码如下"></a>login 中的代码如下</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">session_start();</span><br><span class="line">$url = $_GET[<span class="string">'url'</span>];</span><br><span class="line"><span class="keyword">if</span> (<span class="keyword">isset</span>($_SESSION[<span class="string">'username'</span>])) &#123;</span><br><span class="line">    header(<span class="string">'Location: '</span> . $url . <span class="string">'?session_id='</span> . session_id());</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span> ($_SERVER[<span class="string">'REQUEST_METHOD'</span>] == <span class="string">'POST'</span>) &#123;</span><br><span class="line">    $username = $_POST[<span class="string">'username'</span>];</span><br><span class="line">    $password = $_POST[<span class="string">'password'</span>];</span><br><span class="line">    <span class="keyword">if</span> (($username == <span class="string">'test'</span> || $username == <span class="string">'peter'</span>) &amp;&amp; $password == <span class="string">'123456'</span>) &#123;</span><br><span class="line">        <span class="comment">// 登录成功，跳回原网站</span></span><br><span class="line">        $_SESSION[<span class="string">'username'</span>] = $username;</span><br><span class="line">        <span class="keyword">if</span> ($url) &#123;</span><br><span class="line">            header(<span class="string">'Location: '</span> . $url . <span class="string">'?session_id='</span> . session_id());</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">echo</span> <span class="string">'欢迎您，访问'</span> . $username . <span class="string">'的空间。'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">echo</span> <span class="string">'&lt;h3&gt;账号或密码错误，请输入账号：test，密码：123456&lt;/h3&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">?&gt;</span></span><br><span class="line"></span><br><span class="line">&lt;!doctype html&gt;</span><br><span class="line">&lt;html lang=<span class="string">"en"</span>&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">  &lt;meta charset=<span class="string">"UTF-8"</span>&gt;</span><br><span class="line">  &lt;meta name=<span class="string">"viewport"</span> content=<span class="string">"width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"</span>&gt;</span><br><span class="line">  &lt;meta http-equiv=<span class="string">"X-UA-Compatible"</span> content=<span class="string">"ie=edge"</span>&gt;</span><br><span class="line">  &lt;title&gt;login&lt;/title&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line"></span><br><span class="line">&lt;form action=<span class="string">""</span> method=<span class="string">"post"</span>&gt;</span><br><span class="line">  &lt;h3&gt;来路地址：<span class="meta">&lt;?php</span> <span class="keyword">echo</span> $url; <span class="meta">?&gt;</span>&lt;/h3&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;label <span class="keyword">for</span>=<span class="string">"username"</span>&gt;&lt;input type=<span class="string">"text"</span> name=<span class="string">"username"</span>&gt;&lt;/label&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;label <span class="keyword">for</span>=<span class="string">"password"</span>&gt;&lt;input type=<span class="string">"password"</span> name=<span class="string">"password"</span>&gt;&lt;/label&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;input type=<span class="string">"submit"</span> value=<span class="string">"login"</span>&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/form&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure>
<h2 id="a-和-b-中的代码如下"><a href="#a-和-b-中的代码如下" class="headerlink" title="a 和 b 中的代码如下"></a>a 和 b 中的代码如下</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">$loginUrl = <span class="string">'http://login.oss.centos.local/login.php?url=http://'</span> . $_SERVER[<span class="string">'HTTP_HOST'</span>];</span><br><span class="line"><span class="keyword">if</span> (!<span class="keyword">isset</span>($_GET[<span class="string">'session_id'</span>])) &#123;</span><br><span class="line">    header(<span class="string">'Location: '</span> . $loginUrl);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">session_id($_GET[<span class="string">'session_id'</span>]);</span><br><span class="line">session_start();</span><br><span class="line"></span><br><span class="line">$username = $_SESSION[<span class="string">'username'</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ($username) &#123;</span><br><span class="line">    <span class="keyword">echo</span> <span class="string">"欢迎您，来到$&#123;username&#125;的小屋."</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    header(<span class="string">'Location: '</span> . $loginUrl);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>写在最后，这只是一个简单的 oss 单点登录操作说明，实际中操作更为复杂。</p>
</blockquote>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#系统架构说明"><span class="toc-text">系统架构说明</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#login-中的代码如下"><span class="toc-text">login 中的代码如下</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#a-和-b-中的代码如下"><span class="toc-text">a 和 b 中的代码如下</span></a></li></ol>
  </div>
</aside>
  
    <aside class="passage-copyright">
      <div>本文作者: 紫锦木</div>
      
        <div>
          原文链接: 
          <a href target="_blank">https://www.johnxu.net/articles/cka9gj4zi000emu8o5h2rxhmt.html</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/tags/oss点单登录/"><i class="fa fa-tags"></i>oss点单登录</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    <div class="site-footer-wrapper">
  <footer class="site-footer">
    
    
    <div class="site-footer-col">
      <h5 class="site-footer-title">博客推荐</h5>
      
      <span class="site-footer-item">
        <a href="https://godbmw.com/" target="_blank">GodBMW</a>
      </span>
      
      <span class="site-footer-item">
        <a href="http://ruanyifeng.com/" target="_blank">阮一峰的个人网站</a>
      </span>
      
    </div>
    
    <div class="site-footer-col">
      <h5 class="site-footer-title">抓到我</h5>
      
      <span class="site-footer-item">
        <a href="https://juejin.im/user/5b4ffe335188251afa62cd8a" target="_blank">掘金</a>
      </span>
      
      <span class="site-footer-item">
        <a href="https://segmentfault.com/u/johnxu_58f42b627331b" target="_blank">思否</a>
      </span>
      
      <span class="site-footer-item">
        <a href="https://www.jianshu.com/u/56f6d0e3bae3" target="_blank">简书</a>
      </span>
      
    </div>
    
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
    <div class="site-footer-info">
      <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
    </div>
    
    
    <div class="site-footer-info">
      <i class="fa fa-at"></i> Email: fsyzxz@163.com
    </div>
    
    <div class="site-footer-info">
      <i class="fa fa-copyright"></i>
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div>
    <div class="site-footer-info">
      <a href="http://www.beian.miit.gov.cn" target="_blank">蜀ICP备17000668号</a>
    </div>
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
        <div class="site-layer-reward" id="site-layer-reward" style="display: none;">
          
            <div>
              <img src="/images/wechat.png" alt="WeChat">
              
                <p>WeChat</p>
              
            </div>
          
            <div>
              <img src="/images/alipay.png" alt="AliPay">
              
                <p>AliPay</p>
              
            </div>
          
        </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">
  <div class="bottom-bar-left">
    <a href="javascript:void(0);" data-enable="false">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/articles/cka9gj4zd0008mu8oxl6vztxb.html" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
      <a href="javascript:void(0);" id="site-reward">
        <i class="fa fa-thumbs-up"></i>
      </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
    <a id="share-btn-weibo" href="javascript:void(0);" target="_blank">
      <i class="fa fa-weibo"></i>
    </a>
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
    <a id="share-btn-wechat" href="javascript:void(0);" target="_blank">
      <i class="fa fa-wechat"></i>
    </a>
  
</div>
    


  <script async>
  (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
          bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else {
          bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>




    
  </body>
</html>